<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <todo>
            <todo-title slot="todo-title" v-bind:title="title"></todo-title>
            <todo-items slot="todo-items" v-for="(item,index) in items" v-bind:item=item v-bind:index=" index"
                v-on:remove="removeItems"></todo-items>
        </todo>
    </div>
    <script>
        // 定义 待办事项 组件
        Vue.component("todo", {
            template: '<div><slot name=\'todo-title\'></slot><ul><slot name=\'todo-items\'></slot></ul></div>'
        });
        // 定义 待办事项-标题 组件
        Vue.component("todo-title", {
            props: ['title'],
            template: "<div>{{title}}</div>"
        });
        // 定义 待办事项-内容 组件
        Vue.component("todo-items", {
            props: ['item', 'index'],
            template: "<li>{{index}}--{{item}}<button @click='remove'>删除</button></li>",
            methods: {
                remove: function () {
                    this.$emit("remove")
                }
            }
        })
        var app = new Vue({
            // element的缩写，挂在元素
            el: "#app",
            data: {
                title: '标题1',
                items: ["333", "3444", "55353"]
            },
            methods: {
                removeItems: function (index) {
                    this.items.splice(index, 1)
                }
            }
        })
    </script>
</body>

</html>